<template>
  <div class="link-box">
    <div>
      <el-radio v-model="item.linkType" label="0" @change="linkTypeChange">无</el-radio>
      <el-radio v-model="item.linkType" label="1" @change="linkTypeChange">链接</el-radio>
    </div>
    <div v-if="item.linkType !== '0'">
      <el-input v-model="item.link" class="input" @change="linkChange" placeholder="请输入链接地址"/>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    index: {
      type: Number,
      default: 0
    },
    item: {
      type: Object,
      default: () => {
        return {
          title: "",
          imageUrl: "",
          linkType: "0",
          link: ""
        }
      }
    },
  },
  setup(props, context) {
    const linkTypeChange = (val) => {
      context.emit("change-link-type", props.index, val)
    }
    const linkChange = (val) => {
      context.emit("change-link", props.index, val)
    }
    return {
      linkTypeChange,
      linkChange
    }
  }
}
</script>

<style lang="scss" scoped>
.link-box {
  margin: 0 20px 20px 20px;
  box-sizing: border-box;
  font-size: 14px;
  justify-content: space-between;
  .input {
    margin: 20px 0 0 0;
  }
}
</style>
